package com.backend.serializer;

import com.backend.utils.DatePatternUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.util.Date;

/**
 * @author wangzizh
 **/
public class DateDeserializer extends StdDeserializer<Date> {

  public final static DateDeserializer instance = new DateDeserializer();

  /**
   * 构造方法
   */
  public DateDeserializer() {
    this(null);
  }

  /**
   * 构造方法
   *
   * @param vc Class
   */
  public DateDeserializer(Class<?> vc) {
    super(vc);
  }

  /**
   * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(JsonParser,
   * DeserializationContext)
   */
  @Override
  public Date deserialize(JsonParser p, DeserializationContext ctxt)
      throws IOException {
    return DatePatternUtil.getPatternDate(p.getValueAsString());
  }

}
